package cn.edu.scau.cmi.tangqingning.factoryMethod;

import cn.edu.scau.cmi.tangqingning.simpleFactoryMethod.Insurance;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextArea;

public class FactoryController {

    @FXML
    private TextArea textId;

    @FXML
    private ComboBox<String> comboBox;

	public void Init() {
		// TODO Auto-generated method stub
		ObservableList<String> options = FXCollections.observableArrayList("身体受伤","汽车损坏","人员伤亡", "多种事故");
		System.out.println(options);
		this.comboBox.setItems(options);
		this.comboBox.getSelectionModel().select(0);
	}

	@FXML
    void onShowDataClick(ActionEvent event) {
		Insurance in = null;
        switch(this.comboBox.getValue()) {
	        case "身体受伤": in =  new BruiseFactory().createProduct();break;
	        case "汽车损坏": in = new CarDamagedFactory().createProduct();break;
	        case "人员伤亡": in = new CasualtyFactory().createProduct();break;
	        case "多种事故": in = new AccidentsFactory().createProduct();break;
	        default : this.textId.setText("创建保险错误");break;
        }

		this.textId.setText(in.getData());
    }
}

